/**
 * @param {Fucntion} callback 请求函数
 * @param {Number} timeout 超时时间
*/

function abortFunc(callback, timeout) {
  let wait = new Promise((_, reject) => {
    setTimeout(()=> reject('请求超时'), timeout)
  })
  return Promise.race([callback(), wait])
}

// // 测试
// const timeoutFunc1 = () => new Promise((resole, reject) => setTimeout(()=> resole('t1请求成功'), 4000))
// const timeoutFunc2 = () => new Promise((resole, reject) => setTimeout(()=> resole('t2请求成功'), 6000))
// abortFunc(timeoutFunc1, 5000).then(
//   (value) => console.log(value), // 't1请求成功'
//   (reason) => console.log(reason)
// )
// abortFunc(timeoutFunc2, 5000).then(
//   (value) => console.log(value),
//   (reason) => console.log(reason) // '请求超时'
// )
